#pragma once

// Std
#include <memory>
#include "D3D11Client.h"


class CachedTexture;

typedef struct TILEDESC1 {	//[76 bytes]

	std::unique_ptr<CachedTexture> tex, tex_old, ntex, htex;
	ID3D11ShaderResourceView
		/**tex,		//diffuse texture RGB
		*tex_old,*/	//from previous texture set
		*ltex,		//specular/emissive map RGBA
		/**ntex,		//normal map RGB
		*htex,*/		//heightmap
		*ctex;		//LCC texture

	UINT svtx;	//offset in tile buffer. [0 for not initialized]

	//collision and visibility detection
	float amin, amax, *HMAP;	//maximum and minimum altitude
	D3DXVECTOR3 bsPos;
	float bsRad;

	//links with subtiles
	struct TILEDESC1 *subtile[4];
	DWORD
		flags,	//misc flags
		ofs;	//offset in tile buffer
} TILEDESC1;

//texture coord range
typedef struct TEXCRDRANGE1 {
	float tumin, tumax;
	float tvmin, tvmax;
} TEXCRDRANGE1;

struct TILECRDRANGE {
	TEXCRDRANGE1 range_tex;
	TEXCRDRANGE1 range_norm;
	TEXCRDRANGE1 range_height;
	TEXCRDRANGE1 range_lcover;
};

//Tile textures:
typedef struct TILETEX {	//textures
	CachedTexture * tex, *ntex, *htex;
	ID3D11ShaderResourceView
		//*tex,
		*ltex,
		/**ntex,
		*htex,*/
		*ctex;
} TILETEX;

typedef struct TILERENDERSPEC {
	TILEDESC1 *td;
	D3DXMATRIX mWorld;
	TILETEX Tex;
	TILECRDRANGE RANGE;
	UINT8 hemisphere, level;
	UINT ilat, nlat, ilng, nlng, flag;
	int ncascade;
	//166
} TILERENDERSPEC;


typedef struct TILEVERTEX_LOW {	//46
	D3DXVECTOR3 PosL;
	D3DXVECTOR3 NormL;
	D3DXVECTOR3 TangL;
	D3DXVECTOR2 TCrd;
} TILEVERTEX_LOW;

typedef struct TILEVERTEX_HIGH {
	D3DXVECTOR2 PosL;
	D3DXVECTOR2 TCrd;
	UINT32 flag;
} TILEVERTEX_HIGH;

typedef struct TILEMESH1 {
	ID3D11Buffer *VB, *IB;
	UINT
		nvtx,
		nidx,
		nface;
	D3DXVECTOR3 bsPos;
	float bsRad;
} TILEMESH1;

//======================================
//		File headers
//======================================
#pragma region file headers

#pragma pack( push, 2 )
struct HMAPFILESPEC {
	UINT64 hidx;
	DWORD flags;
	DWORD subidx[4];
};
#pragma pack( pop )

//24 byte
struct LCOVERFILESPEC {
	DWORD lidx;
	DWORD flags;
	DWORD subidx[4];
};

#pragma endregion

#define NODATA 0xFF
#define NOTILE 0xFFFFFFFF
#define NOTILE64 0xFFFFFFFFFFFFFFFFU


